import moment from 'moment';
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  plan_list,
  plan_table_detail,
  save_or_update,
  get_graphic_manager,
  plan_detail,
  getContractVoList,
  operation_detail,
  get_assess,
  check_order,
  planRemark,
  queryOneResord,
  // updateBudget,
  cancelPlanByIds,
  controlqueryPhase,
  controlupdatePhase,
} from "@/api/smart/schedul/c.js";
import { graphic_list } from "@/api/smart/schedul/b.js";

import {
  useruser_list,
} from "@/api/smart/schedul/f.js";
import { getDicType, getcompany, get_simple_organization, getStationByCompanyId } from "@/api/common.js";
import { getUserInfo } from "@/utils/auth.js";
import { getDisClostDetail } from "@/api/internetSales/projectClarifi.js";
export default {
  mixins: [mixin],
  data() {
    return {
      showCardNav2: false,
      UserInfo: '',
      companylist: [], //公司
      sitelist: [],//站点
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      loading: false,
      currenindex: 1,
      contractTypelist: [
        { value: "供应中", id: 1 },
        { value: "供应完成", id: 2 },
      ],
      /*表格数据*/
      table: [
        {
          label: "合同号",
          width: "",
          prop: "contractNo",
          status: true,
        },
        {
          label: "工程名称",
          width: "",
          prop: "engineeringName",
          status: true,
        },
        {
          label: "客户名称",
          width: "",
          prop: "customerName",
          status: true,
        },
        {
          label: "交底时间",
          width: "",
          prop: "limitFinishTime",
          status: true,
        },
        {
          label: "负责人",
          width: "",
          prop: "chargePerson",
          status: true,
        },
        {
          label: "预估用砼量",
          width: "",
          prop: "expectedAmount",
          status: true,
        },
        {
          label: "累计浇筑量（方）",
          width: "",
          prop: "totalPoureCount",
          status: true,
        },
        {
          label: "累计订单数量",
          width: "",
          prop: "totalOrderCount",
          status: true,
        },
        {
          label: "待审核",
          width: "",
          prop: "notReviewCount",
          status: true,
        },
        {
          label: "用料计划",
          width: "",
          prop: "",
          status: true,
        },
        {
          label: "供应阶段",
          width: "150",
          prop: "",
          status: true,
        },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        structuralParts: [
          {
            required: true,
            message: "请输入浇筑部位",
            trigger: "change",
          },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "change",
          },
        ],
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "change",
          },
        ],
        phoneNum: [
          {
            required: true,
            message: "请输入联系电话",
            trigger: "change",
          },
          { min: 11, max: 11, message: "手机号格式错误", trigger: "change" },
        ],
      },
      /*添加表单数据*/
      rules2: {
        person: [
          {
            required: true,
            message: "请输入联系人",
            trigger: "change",
          },
        ],
        phoneNum: [
          { required: true, message: "请输入联系电话", trigger: "change", },
          { min: 11, max: 11, message: "手机号格式错误", trigger: "change" },
        ],
        pouringTime: [
          {
            required: true,
            message: "请选择浇筑时间",
            trigger: "change",
          },
        ],
        pouringHigh: [
          {
            required: true,
            message: "请输入泵送高度",
            trigger: "change",
          },
        ],
        noteName: [
          {
            required: true,
            message: "请输入票单名称",
            trigger: "change",
          },
        ],
      },
      rules2_2: {
        pointId: [
          {
            required: true,
            message: "请选择供应站点名称",
            trigger: "change",
          },
        ],
        settleId: [
          {
            required: true,
            message: "请选择结算方式",
            trigger: "change",
          },
        ],
        lossNumId: [
          {
            required: true,
            message: "请选择损耗量",
            trigger: "change",
          },
        ],
        foremanId: [
          {
            required: true,
            message: "请输入前场工长",
            trigger: "change",
          },
        ],
      },
      formData: {
        strengthGradeId: "", //强度等级
        performanceGradeIdList: [],
        meterialRequirementsIdList: [],
        specialRequirementsIdList: [],
        otherRequirementsIdList: [],
        admixtureRequirementsIdList: [],
        pouringMethodIdList: [],
        pouringTime: "", //浇筑时间
      },
      engineeringRow: {},//工程对象
      engineeringName: "",
      engineeringId: "", //工程id
      id: "", //计划id
      ToViewType: false,
      toViewList: [],
      tableInfo: {},
      addDialog: false,
      addDialog2: false,
      chooseType: false,
      engineeringManagement: [],
      strengthGradeList: [], //强度list
      performanceGradeList: [], //性能等级list
      meterialRequirementsList: [], //材料要求list
      specialRequirementsList: [], //特殊要求list
      otherRequirementsList: [], //其他要求list
      admixtureRequirementsList: [], //外加剂要求list
      pouringMethodList: [], //浇筑方式list
      structuralPartsList: [], //浇筑部位
      goodPriceList: [],
      formData2: {
        performanceGradeIdList: [],
        meterialRequirementsIdList: [],
        specialRequirementsIdList: [],
        otherRequirementsIdList: [],
        admixtureRequirementsIdList: [],
        pouringMethodIdList: [],
      },
      formData2_2: { pointId: '', settleId: '', lossNumId: '', foremanId: '' },
      assess: {},
      ListArr: [],
      toViewList2: [],
      searchText: "",
      foremanIdList: [],
      ToViewFun3Name: "",
      radio: {},
      marginNumberList: [],
      budgetPersonIdList: [],
      remarkList: [],
      bussinessVisible: false,
      buspointArr: [],
      servicePoint: '',
      buspointids: [],
      query: {},
      ids: [],
      isReadOnly: false,
      tableParam: {
        engineeringName: "",
        contractNo: '',
        budgetPersonId: '',
      },
    };
  },
  watch: {
    tableData: {
      async handler() {
        for (let i = 0; i < this.tableData.length; i++) {
          await controlqueryPhase({ engineeringId: this.tableData[i].engineeringId, type: 1 }).then((res) => {
            res.data.push({ id: '1', supplyPhase: '无' }, { id: '2', supplyPhase: '供应完成' })
            this.tableData[i].phaseIdList = res.data
            this.tableData[i].phaseId0 = this.tableData[i].phaseId
          })
        }
        this.$forceUpdate()
      }
    }
  },
  async created() {
    this.UserInfo = await getUserInfo();
    if (this.UserInfo.adminStatus == 1) {
      /**通过typeId为公司类型id查询所有公司 */
      getcompany({ typeId: "19da56b9e85648059e3cf1e7da497da4" }).then((res) => {
        this.companylist = res.data;
      });
    }
    this.tableParam = {
      ...this.tableParam,
      name: "",
      phase: 1
    };
    /**角色：预算员id不能改 */
    await useruser_list({ roleId: "48d84b503be7484ca1b5c2eade1ff004" }).then(
      (res) => {
        this.budgetPersonIdList = res.data;
        let id = this.budgetPersonIdList.findIndex((v) => v.userId == this.UserInfo.userId)
        if (id != -1) {
          this.tableParam.budgetPersonId = this.budgetPersonIdList[id].userId
        }
        this.gettableData();
      }
    );
    getDicType({
      code: "marginNumber",
    }).then((res) => {
      this.marginNumberList = res.data.items;
    });
    getDicType({
      code: "market",
    }).then((res) => {
      this.buspointArr = res.data.items;
    });
  },
  methods: {
    controlupdatePhaseFun(row) {
      if (row.phaseId0 != row.phaseId) {
        this.$confirm('是否修改供应阶段为：' + row.phaseIdList.find(res => res.id == row.phaseId0).supplyPhase, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'bottom_all_two',
          confirmButtonClass: 'bottom_all',
          type: 'warning'
        }).then(() => {
          let json = {
            engineeringId: row.engineeringId,
            supplyPhaseId: row.phaseId0,
            supplyPhase: row.phaseIdList.find(res => res.id == row.phaseId0).supplyPhase
          }
          controlupdatePhase(json).then((res) => {
            if (res.code == 1001) {
              this.tableData = []
              this.$message({
                message: "设置成功",
                type: "success",
              });
              this.gettableData();
            }
          })
        }).catch(() => {
          row.phaseId0 = row.phaseId
          console.log(row);
        })
      }
    },
    choose(num) {
      this.currenindex = num;
      this.tableParam.phase = this.currenindex
      this.gettableData();
    },
    handleSelectionChange(val) {
      this.ids = val
    },
    cancelPlanByIdsFun() {
      if (this.ids.length == 0) {
        this.$message({
          message: '请选择要操作的数据项',
          type: 'warning'
        });
        return;
      }
      this.$confirm('此操作将取消订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let arr = this.ids.map((res) => res.id)
        cancelPlanByIds(arr).then((res) => {
          if (res.code == 1001) {
            this.ids = []
            this.ToViewFun()
            this.$message({
              type: 'success',
              message: '订单取消成功!'
            });
          }
        })
      })
    },
    /**
     * @Description: 选择管控业务点
     * @Param: 
     * @Author: wangwangwang
     */
    choiseBussinessPoint() {
      this.bussinessVisible = true;
    },
    handlePoint() {
      const newData = this.buspointArr.filter(item => this.buspointids.some(items => item.id === items));
      console.log(newData)
      this.servicePoint = newData.map(item => item.itemName).join(',');
      this.formData2.servicePoint = JSON.stringify(newData.map(item => ({ id: item.id, name: item.itemName, type: 1 })));
      this.bussinessVisible = false;
    },
    /**通过站点查询公司 */
    get_simple_organizationFun(id) {
      get_simple_organization({ id: id }).then((res) => {
        this.formData2_2.companyId = res.data.id
        this.formData2_2.company = res.data.name
      });//查询站点所属公司
    },
    /*根据公司获取站点*/
    async setstationIdlist(companyId) {
      await getStationByCompanyId({ id: companyId }).then((res) => {
        this.sitelist = res.data.map((v) => {
          return {
            id: v.stationId,
            name: v.stationName
          }
        })
      });
    },
    /**预算员设置 */
    // budgetPersonIdFun(e) {
    //   let obj = this.budgetPersonIdList.find((v) => v.userId == e.budgetPersonId)
    //   let json = {
    //     engineeringId: e.engineeringId,//下拉框所在行记录中返回的engineeringId字段值
    //     userId: e.budgetPersonId,//预算员ID
    //     name: obj.userName,//预算员名字
    //     postId: obj.stationId,
    //     phone: obj.stationName
    //   }
    //   updateBudget(json).then((res) => {
    //     if (res.code == 1001) {
    //       this.$message({
    //         message: "设置成功",
    //         type: "success",
    //       });
    //     }
    //   })
    // },
    addDialogFun() {
      this.addDialog = true;
      this.formData = this.$options.data().formData
      this.formData.pouringTime = `${moment().add(1, 'days').format('YYYY-MM-DD')} 08:00:00`
      this.formData.engineeringName = this.engineeringName;
      graphic_list({ engineeringId: this.engineeringId }).then((res) => {
        this.structuralPartsList = res.data;
      });
    },
    radioAddFun() {
      //作业安排-泵送，运输，泵管；选择后的显示和赋值
      this.chooseType = false;
      if (this.ToViewFun3Name == "选择泵送队") {
        this.formData2_2.pumpingTeam =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.pumpingTeamId = this.radio.supplierId;
      } else if (this.ToViewFun3Name == "选择罐车合同") {
        this.formData2_2.tankCar =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.tankCarId = this.radio.supplierId;
      } else if (this.ToViewFun3Name == "选择泵管单位") {
        this.formData2_2.pipeName =
          this.radio.contractNumber + ":" + this.radio.supplierName;
        this.formData2_2.pipeId = this.radio.supplierId;
      }
    },
    radioFun(res) {
      //作业安排-泵送，运输，泵管；的单选
      this.radio = res;
      console.log(this.radio);
    },
    async ToViewFun3(name) {
      //作业安排-泵送，运输，泵管；的弹出列表
      this.chooseType = true;
      this.radio = {};
      let id = "";
      if (name == "泵送") {
        this.ToViewFun3Name = "选择泵送队";
        await getContractVoList({
          contractTypeId: 3,
          facilityType: 1,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pumpingTeamId;
        });
      } else if (name == "运输") {
        this.ToViewFun3Name = "选择罐车合同";
        await getContractVoList({
          contractTypeId: 2,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.tankCarId;
        });
      } else if (name == "泵管") {
        this.ToViewFun3Name = "选择泵管单位";
        await getContractVoList({
          contractTypeId: 4,
        }).then((res) => {
          this.toViewList2 = res.data;
          id = this.formData2_2.pipeId;
        });
      }
      console.log(JSON.parse(JSON.stringify(this.toViewList2)));
      this.toViewList2.forEach((v) => {
        if (v.supplierId == id) {
          console.log(id);
          this.radio = v;
          console.log(JSON.parse(JSON.stringify(this.radio)));
        }
      });
    },
    submit2(approvalStatus) {
      this.$refs.reffromData2.validate((valid) => {
        if (valid) {
          this.$refs.reffromData2_2.validate((valid) => {
            if (valid) {
              //通过和未通过
              this.formData2.approvalStatus = approvalStatus;
              //性能等级-开始数据重装
              if (this.formData2.performanceGradeIdList.length > 0) {
                let arr = [];
                this.formData2.performanceGradeIdList.forEach((v) => {
                  this.performanceGradeList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.performanceGradeId = arr;
                this.formData2.performanceGradeId = JSON.stringify(this.formData2.performanceGradeId);
                this.formData2.performanceGrade = this.formData2.performanceGradeId;
              }
              //材料要求-开始数据重装
              if (this.formData2.meterialRequirementsIdList.length > 0) {
                let arr = [];
                this.formData2.meterialRequirementsIdList.forEach((v) => {
                  this.meterialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.meterialRequirementsId = arr;
                this.formData2.meterialRequirementsId = JSON.stringify(this.formData2.meterialRequirementsId);
                this.formData2.meterialRequirements = this.formData2.meterialRequirementsId;
              }
              //特殊要求-开始数据重装
              if (this.formData2.specialRequirementsIdList.length > 0) {
                let arr = [];
                this.formData2.specialRequirementsIdList.forEach((v) => {
                  this.specialRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.specialRequirementsId = arr;
                this.formData2.specialRequirementsId = JSON.stringify(this.formData2.specialRequirementsId);
                this.formData2.specialRequirements = this.formData2.specialRequirementsId;
              }
              //其他要求-开始数据重装
              if (this.formData2.otherRequirementsIdList.length > 0) {
                let arr = [];
                this.formData2.otherRequirementsIdList.forEach((v) => {
                  this.otherRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.otherRequirementsId = arr;
                this.formData2.otherRequirementsId = JSON.stringify(this.formData2.otherRequirementsId);
                this.formData2.otherRequirements = this.formData2.otherRequirementsId;
              }
              //外加剂要求-开始数据重装
              if (this.formData2.admixtureRequirementsIdList.length > 0) {
                let arr = [];
                this.formData2.admixtureRequirementsIdList.forEach((v) => {
                  this.admixtureRequirementsList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                      });
                    }
                  });
                });
                this.formData2.admixtureRequirements = arr;
                this.formData2.admixtureRequirements = JSON.stringify(this.formData2.admixtureRequirements);
              }
              //浇筑方式-开始数据重装
              if (this.formData2.pouringMethodIdList.length > 0) {
                let arr = [];
                this.formData2.pouringMethodIdList.forEach((v) => {
                  this.pouringMethodList.forEach((v2) => {
                    if (v == v2.id) {
                      arr.push({
                        id: v,
                        name: v2.name,
                        type: v2.type,
                      });
                    }
                  });
                });
                this.formData2.pouringMethod = arr;
                this.formData2.pouringMethod = JSON.stringify(this.formData2.pouringMethod);
              }
              this.formData2.customerCheckStatus = 0;

              let obj = {
                isAudit: 1,
                arrangement: this.formData2_2,
                engineeringPlan: { ...this.formData2, lossNum: this.formData2_2.lossNum, lossNumId: this.formData2_2.lossNumId },
                remark: this.formData2_2.remark,//客户订单备注修改
              };
              check_order(obj).then((res) => {
                if (res.code == 1001) {
                  this.addDialog2 = false;
                  this.$message({
                    message: "操作成功",
                    type: "success",
                  });
                  this.ToViewFun();
                  this.gettableData();
                }
              });
            } else {
              return false;
            }
          });
        } else {
          return false;
        }
      });
    },
    get_graphic_managerFun() {
      //工程图算查询-浇筑部位列表的查询
      let obj = {
        id: this.engineeringId,
        searchText: this.searchText,
      };
      get_graphic_manager(obj).then((res) => {
        this.ListArr = res.data;
      });
    },
    /**点击审核*/
    async ToViewFun2(e, type) {
      this.addDialog2 = true;
      this.isReadOnly = type;
      this.$nextTick(async () => {
        this.$data.formData2 = this.$options.data().formData2
        this.$refs.reffromData2.clearValidate()
        await this.setstationIdlist(e.companyId)
        this.id = e.id;
        this.remarkList = []
        this.searchText = e.structuralParts
        this.get_graphic_managerFun()
        /**历史备注 */
        planRemark({ planId: e.id }).then((res) => {
          this.remarkList = res.data
        })
        plan_detail({ id: this.id }).then((res) => {
          //获取订单信息
          this.formData2 = { ...this.formData2, ...res.data };
          this.formData2.noteName = this.formData2.productName;
          if (res.data.servicePoint) {
            this.servicePoint = JSON.parse(res.data.servicePoint).map(item => item.name).join(',');
          }
          operation_detail({
            //获取作业安排信息
            planId: this.id,
            enginnerId: this.engineeringId,
          }).then((res) => {
            this.formData2_2 = { ...this.formData2_2, ...res.data };
            console.log(res.data)
            this.formData2_2.settleId = res.data.settleId
            if (this.formData2_2.pointId && this.sitelist) {
              let type = this.sitelist.findIndex((v) => v.id == this.formData2_2.pointId)
              if (type == -1) {
                this.formData2_2.pointId = ''
              }
            }
            get_assess({ engineeringId: this.engineeringId }).then((res) => {
              if (res.data) {
                this.assess = res.data;
              }
            });
            if (this.formData2.performanceGradeId) {
              this.formData2.performanceGradeIdList = JSON.parse(this.formData2.performanceGradeId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.performanceGradeIdList = [];
            }
            if (this.formData2.meterialRequirementsId) {
              this.formData2.meterialRequirementsIdList = JSON.parse(this.formData2.meterialRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.meterialRequirementsIdList = [];
            }
            if (this.formData2.specialRequirementsId) {
              this.formData2.specialRequirementsIdList = JSON.parse(this.formData2.specialRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.specialRequirementsIdList = [];
            }
            if (this.formData2.otherRequirementsId) {
              this.formData2.otherRequirementsIdList = JSON.parse(this.formData2.otherRequirementsId).map((v) => {
                return v.id
              });
            } else {
              this.formData2.otherRequirementsIdList = [];
            }
            if (this.formData2.admixtureRequirements) {
              this.formData2.admixtureRequirementsIdList = JSON.parse(this.formData2.admixtureRequirements).map((v) => {
                return v.id
              });
            } else {
              this.formData2.admixtureRequirementsIdList = [];
            }
            if (this.formData2.pouringMethod) {
              this.formData2.pouringMethodIdList = JSON.parse(this.formData2.pouringMethod).map((v) => {
                return v.id
              });
            } else {
              this.formData2.pouringMethodIdList = [];
            }
            this.formData2_2.lossNumId = res.data.lossNumId || ''
            this.$refs.reffromData2_2.clearValidate()
          });
        });
        /**
         * @Description: 获取工程的增值服务项
         * @param {*}
         * @Author: wangwangwang
         */  
        if (type) {
          queryOneResord({ engineeringId: this.engineeringId }).then(res => {
            if (res.code === 1001) {
              const newData = res.data.servicePoint ? JSON.parse(res.data.servicePoint) : [];
              if (newData.length) {
                this.servicePoint = newData.map(item => item.name).join(',');
                this.buspointids = newData.map(item => item.id);
              }
            }
          })
        }
      })
    },
    /**
      查看用料计划详情
      当e存在时，从主列表进入，否则是自身搜索或者处理完成返回这个页面。
    **/
    ToViewFun(e) {
      this.ids = []
      //查看
      this.ToViewType = true;
      if (e) {
        this.tableInfo = {}
        this.query = {}
        this.engineeringRow = e
        this.engineeringName = e.engineeringName;
        this.formData.engineeringName = e.engineeringName;
        this.engineeringId = e.engineeringId;
        this.tableInfo.engineeringName = e.engineeringName;
        this.tableInfo.customerName = e.customerName;
        this.tableInfo.totalPoureCount = e.totalPoureCount;
        this.tableInfo.engineeringName = e.engineeringName;
        this.tableInfo.phaseId0 = e.phaseId0;
        this.getDisClostDisAddCostFun(e.engineeringId)
      }
      plan_list({
        engineeringId: this.engineeringId, ...this.query
      }).then((res) => {
        this.toViewList = res.data;
      });
      plan_table_detail({
        engineeringId: this.engineeringId,
      }).then((res) => {
        if (res.data) {
          this.tableInfo.limitEstimateNum = res.data.limitEstimateNum;
          this.tableInfo.limitFinishTime = res.data.limitFinishTime;
        }
      });
    },
    init() {
      /*重置数据*/
      this.tableParam.contractNo = "";
      this.tableParam.engineeringName = "";
      let id = this.budgetPersonIdList.findIndex((v) => v.userId == this.UserInfo.userId)
      if (id != -1) {
        this.tableParam.budgetPersonId = this.budgetPersonIdList[id].userId
      }
      this.gettableData();
    },
    //添加计划
    submit() {
      this.$refs.reffromData.validate((valid) => {
        if (valid) {
          this.formData.engineeringName = this.engineeringName;
          this.formData.engineeringId = this.engineeringId;
          this.formData.strengthGrade = this.$fromatTable(
            this.strengthGradeList,
            this.formData.strengthGradeId,
            "id",
            "name"
          );
          //性能等级-开始数据重装
          if (this.formData.performanceGradeIdList.length > 0) {
            let arr = [];
            this.formData.performanceGradeIdList.forEach((v) => {
              this.performanceGradeList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.performanceGradeId = arr;
            this.formData.performanceGradeId = JSON.stringify(this.formData.performanceGradeId);
            this.formData.performanceGrade = this.formData.performanceGradeId;
          }
          //材料要求-开始数据重装
          if (this.formData.meterialRequirementsIdList.length > 0) {
            let arr = [];
            this.formData.meterialRequirementsIdList.forEach((v) => {
              this.meterialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.meterialRequirementsId = arr;
            this.formData.meterialRequirementsId = JSON.stringify(this.formData.meterialRequirementsId);
            this.formData.meterialRequirements = this.formData.meterialRequirementsId;
          }
          //特殊要求-开始数据重装
          if (this.formData.specialRequirementsIdList.length > 0) {
            let arr = [];
            this.formData.specialRequirementsIdList.forEach((v) => {
              this.specialRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.specialRequirementsId = arr;
            this.formData.specialRequirementsId = JSON.stringify(this.formData.specialRequirementsId);
            this.formData.specialRequirements = this.formData.specialRequirementsId;
          }
          //其他要求-开始数据重装
          if (this.formData.otherRequirementsIdList.length > 0) {
            let arr = [];
            this.formData.otherRequirementsIdList.forEach((v) => {
              this.otherRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.otherRequirementsId = arr;
            this.formData.otherRequirementsId = JSON.stringify(this.formData.otherRequirementsId);
            this.formData.otherRequirements = this.formData.otherRequirementsId;
          }
          //外加剂要求-开始数据重装
          if (this.formData.admixtureRequirementsIdList.length > 0) {
            let arr = [];
            this.formData.admixtureRequirementsIdList.forEach((v) => {
              this.admixtureRequirementsList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                  });
                }
              });
            });
            this.formData.admixtureRequirements = arr;
            this.formData.admixtureRequirements = JSON.stringify(this.formData.admixtureRequirements);
          }
          //浇筑方式-开始数据重装
          if (this.formData.pouringMethodIdList.length > 0) {
            let arr = [];
            this.formData.pouringMethodIdList.forEach((v) => {
              this.pouringMethodList.forEach((v2) => {
                if (v == v2.id) {
                  arr.push({
                    id: v,
                    name: v2.name,
                    type: v2.type,
                  });
                }
              });
            });
            this.formData.pouringMethod = arr;
          }
          this.formData.pouringMethod = JSON.stringify(this.formData.pouringMethod);
          this.formData.approvalStatus = 1;
          this.structuralPartsFun()
          this.formData.companyId = this.engineeringRow.companyId
          this.formData.companyName = this.engineeringRow.companyName
          save_or_update(this.formData).then((res) => {
            if (res.code == 1001) {
              this.addDialog = false;
              this.$message({
                message: "添加成功",
                type: "success",
              });
              this.ToViewFun();
              this.gettableData();
            }
          });
        } else {
          return false;
        }
      });
    },
    chongZhi() {
      this.$data.formData = this.$options.data().formData
      setTimeout(() => {
        this.$refs.reffromData.clearValidate()
      }, 100)
    },
    structuralPartsCheckFun() {
      this.formData.strengthGradeId = ''
      this.formData.performanceGradeIdList = ''
      this.formData.meterialRequirementsIdList = ''
      this.formData.specialRequirementsIdList = ''
      this.formData.otherRequirementsIdList = ''
      this.formData.admixtureRequirementsIdList = ''
      let item = this.structuralPartsList.find((v) => v.id == this.formData.structuralParts)
      if (item) {
        this.formData.strengthGradeId = JSON.parse(item.strengthGrade)[0].id
        if (item.performanceGrade) {
          this.formData.performanceGradeIdList = JSON.parse(item.performanceGrade).map((v) => v.id)
        }
        if (item.meterialRequirements) {
          this.formData.meterialRequirementsIdList = JSON.parse(item.meterialRequirements).map((v) => v.id)
        }
        if (item.specialRequirements) {
          this.formData.specialRequirementsIdList = JSON.parse(item.specialRequirements).map((v) => v.id)
        }
        if (item.otherRequirements) {
          this.formData.otherRequirementsIdList = JSON.parse(item.otherRequirements).map((v) => v.id)
        }
        if (item.admixtureRequirements) {
          this.formData.admixtureRequirementsIdList = JSON.parse(item.admixtureRequirements).map((v) => v.id)
        }
      }
    },
    structuralPartsFun() {
      console.log(this.structuralPartsList, this.formData.structuralParts);
      let item = this.structuralPartsList.find((v) => v.id == this.formData.structuralParts)
      if (item) {
        this.formData.structuralPartsId = this.formData.structuralParts
        this.formData.structuralParts = item.structuralParts
      } else {
        this.formData.structuralPartsId = ''
      }
    },
    /**查询该工程的强度等级+各项要求+浇筑部位 */
    getDisClostDisAddCostFun(id) {
      getDisClostDetail({ id }).then(res => {
        if (res.code === 1001) {
          this.strengthGradeList = JSON.parse(res.data.strengthGrade);
          this.performanceGradeList = JSON.parse(res.data.performanceRate);
          //材料要求pouringMethodList
          this.meterialRequirementsList = JSON.parse(res.data.materialRequirements);
          //特殊要求
          this.specialRequirementsList = JSON.parse(res.data.specialRequirements);
          //外加剂要求
          this.admixtureRequirementsList = JSON.parse(res.data.admixtureRequirements);
          //其他要求
          this.otherRequirementsList = JSON.parse(res.data.otherRequirements);
          //浇筑方式
          this.pouringMethodList = JSON.parse(res.data.pumpType);
        }
      })
    },
    selectableFun(row) {
      if (row.approvalStatus !== 4) {
        return true
      }
    },
    /**富余量：判断选项是否是数字 */
    numberType(e) {
      let reg = new RegExp(/^\d+$|^\d*\.\d+$/)
      if (reg.test(e)) {
        return false;
      } else {
        return true;
      }
    },
  },
  filters: {
    pouringMethodFilter(e) {
      let table = e.map((res) => res.name)
      let text = table.join('、')
      return text
    }
  }
};
